home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / MenuPopUp / MenuPopUp.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.2 KB  |  427 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.MediaTracker;
  10. import java.awt.Menu;
  11. import java.awt.MenuItem;
  12. import java.awt.PopupMenu;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.MouseEvent;
  16. import java.awt.event.MouseListener;
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import java.net.URLEncoder;
  20. import java.text.DateFormat;
  21. import java.util.EventObject;
  22.  
  23. public class MenuPopUp extends Applet implements MouseListener, ActionListener {
  24.    // $FF: renamed from: wi int
  25.    private int field_0;
  26.    // $FF: renamed from: he int
  27.    private int field_1;
  28.    private PopupMenu pop;
  29.    private String statusBarText;
  30.    private AudioClip sound;
  31.    private AudioClip clicSound;
  32.    private boolean loopSound;
  33.    private Color backColor;
  34.    private Color enterBackColor;
  35.    private String mode = "enter";
  36.    private Image backImage;
  37.    private String backImageName;
  38.    private boolean loaded = false;
  39.    private boolean isBackImage = false;
  40.    private boolean paintable = false;
  41.    // $FF: renamed from: b java.awt.Graphics
  42.    private Graphics field_2;
  43.    private Image buffer;
  44.    private int decy;
  45.    private int decx;
  46.    private int wiBack;
  47.    private int heBack;
  48.    private int text_height;
  49.    private int string_width;
  50.    private Color textColor;
  51.    private String text;
  52.    // $FF: renamed from: df java.text.DateFormat
  53.    private DateFormat field_3;
  54.    // $FF: renamed from: fm java.awt.FontMetrics
  55.    private FontMetrics field_4;
  56.    private boolean isText = false;
  57.    private String location;
  58.  
  59.    public String getAppletInfo() {
  60.       return "Name: MenuPopUp\r\nAuthor: Taiji Software\r\n";
  61.    }
  62.  
  63.    public void register() {
  64.       try {
  65.          URL u = new URL("http://www.taijisoftware.com");
  66.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  67.          this.stop();
  68.       } catch (Exception e) {
  69.          System.out.println(e);
  70.          this.stop();
  71.       }
  72.    }
  73.  
  74.    public void init() {
  75.       String codeBase = null;
  76.  
  77.       try {
  78.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  79.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  80.          codeBase = codeBase.toUpperCase();
  81.       } catch (Exception var11) {
  82.       }
  83.  
  84.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  85.          String regCode = ((Applet)this).getParameter("registration_code");
  86.          if (regCode == null) {
  87.             regCode = ((Applet)this).getParameter("reg_domain");
  88.             if (regCode == null) {
  89.                this.register();
  90.             } else {
  91.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  92.                   codeBase = "WWW." + codeBase;
  93.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  94.                   codeBase = codeBase.substring(4);
  95.                }
  96.  
  97.                char[] chars = new char[codeBase.length()];
  98.                codeBase.getChars(0, codeBase.length(), chars, 0);
  99.                String key = new String("haricot");
  100.                char[] chars2 = new char[key.length()];
  101.                key.getChars(0, key.length(), chars2, 0);
  102.  
  103.                for(int i = 0; i < codeBase.length(); ++i) {
  104.                   int j;
  105.                   if (i >= key.length()) {
  106.                      j = i - key.length() * (i / key.length());
  107.                   } else {
  108.                      j = i;
  109.                   }
  110.  
  111.                   chars[i] += chars2[j];
  112.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  113.                }
  114.  
  115.                String res = new String(chars);
  116.                if (!res.equalsIgnoreCase(regCode)) {
  117.                   this.register();
  118.                }
  119.             }
  120.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  121.             this.register();
  122.          }
  123.       }
  124.  
  125.       this.getParameters();
  126.       this.pop = new PopupMenu();
  127.       this.giveMenu("");
  128.       ((Component)this).add(this.pop);
  129.       if (this.isBackImage) {
  130.          MediaTracker tracker = new MediaTracker(this);
  131.          this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  132.          tracker.addImage(this.backImage, 0);
  133.  
  134.          try {
  135.             tracker.waitForAll();
  136.             this.loaded = !tracker.isErrorAny();
  137.             this.paintable = !tracker.isErrorAny();
  138.          } catch (InterruptedException var10) {
  139.             this.stop();
  140.          }
  141.  
  142.          if (!this.loaded) {
  143.             this.stop();
  144.             return;
  145.          }
  146.  
  147.          this.wiBack = this.backImage.getWidth(this);
  148.          this.heBack = this.backImage.getHeight(this);
  149.       }
  150.  
  151.       this.buffer = ((Component)this).createImage(this.field_0, this.field_1);
  152.       this.field_2 = this.buffer.getGraphics();
  153.  
  154.       try {
  155.          Font f = new Font("TimesRoman", 1, this.text_height);
  156.          this.field_2.setFont(f);
  157.       } catch (Exception var9) {
  158.          Font f = this.field_2.getFont();
  159.          this.field_2.setFont(new Font(f.getName(), f.getStyle(), this.text_height));
  160.       }
  161.  
  162.       if (this.isText) {
  163.          this.field_4 = this.field_2.getFontMetrics();
  164.          this.string_width = this.field_4.stringWidth(this.text);
  165.          if (this.decx == 0) {
  166.             this.decx = (this.field_0 - this.string_width) / 2;
  167.          }
  168.  
  169.          if (this.decy == 0) {
  170.             this.decy = (this.field_1 + this.field_4.getMaxAscent() - this.field_4.getMaxDescent()) / 2 - this.text_height;
  171.          }
  172.  
  173.          this.field_2.setColor(this.textColor);
  174.       }
  175.  
  176.       if (this.sound != null) {
  177.          if (this.loopSound) {
  178.             this.sound.loop();
  179.          } else {
  180.             this.sound.play();
  181.          }
  182.       }
  183.  
  184.       this.paintable = true;
  185.       ((Component)this).repaint();
  186.    }
  187.  
  188.    public Menu giveMenu(String prof) {
  189.       Menu menu = new Menu(((Applet)this).getParameter("text" + prof));
  190.       int i = 0;
  191.  
  192.       while(true) {
  193.          ++i;
  194.          String prof2 = prof + "#" + Integer.toString(i);
  195.          if (((Applet)this).getParameter("text" + prof2) == null) {
  196.             return menu;
  197.          }
  198.  
  199.          String s = ((Applet)this).getParameter("text" + prof2 + "#1");
  200.          if (s == null) {
  201.             s = ((Applet)this).getParameter("text" + prof2);
  202.             if (s.equals("-")) {
  203.                if (prof.equals("")) {
  204.                   this.pop.addSeparator();
  205.                } else {
  206.                   menu.addSeparator();
  207.                }
  208.             } else {
  209.                MenuItem menuitem = new MenuItem(((Applet)this).getParameter("text" + prof2));
  210.                menuitem.addActionListener(this);
  211.                menuitem.setActionCommand(((Applet)this).getParameter("link" + prof2));
  212.                if (prof.equals("")) {
  213.                   this.pop.add(menuitem);
  214.                } else {
  215.                   menu.add(menuitem);
  216.                }
  217.             }
  218.          } else if (prof.equals("")) {
  219.             this.pop.add(this.giveMenu(prof2));
  220.          } else {
  221.             menu.add(this.giveMenu(prof2));
  222.          }
  223.       }
  224.    }
  225.  
  226.    public void getParameters() {
  227.       this.field_0 = ((Component)this).getSize().width;
  228.       this.field_1 = ((Component)this).getSize().height;
  229.       this.mode = ((Applet)this).getParameter("mode");
  230.       this.location = ((Applet)this).getParameter("location");
  231.       this.backColor = this.getColor("background_color");
  232.       ((Component)this).setBackground(this.backColor);
  233.       this.enterBackColor = this.getColor("enter_background_color");
  234.       this.textColor = this.getColor("text_color");
  235.       this.text = ((Applet)this).getParameter("text");
  236.       if (this.text != null) {
  237.          this.isText = true;
  238.       }
  239.  
  240.       String s = ((Applet)this).getParameter("text_height");
  241.       if (s != null) {
  242.          this.text_height = Integer.parseInt(s);
  243.       }
  244.  
  245.       s = ((Applet)this).getParameter("height_shift");
  246.       if (s != null) {
  247.          this.decy = Integer.parseInt(s);
  248.       }
  249.  
  250.       s = ((Applet)this).getParameter("width_shift");
  251.       if (s != null) {
  252.          this.decx = Integer.parseInt(s);
  253.       }
  254.  
  255.       this.backImageName = ((Applet)this).getParameter("background_image");
  256.       if (this.backImageName != null) {
  257.          this.isBackImage = true;
  258.       }
  259.  
  260.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  261.       s = ((Applet)this).getParameter("sound_name");
  262.       if (s != null) {
  263.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  264.       }
  265.  
  266.       s = ((Applet)this).getParameter("loop_sound");
  267.       if (s != null) {
  268.          if (s.equals("yes")) {
  269.             this.loopSound = true;
  270.          } else {
  271.             this.loopSound = false;
  272.          }
  273.       }
  274.  
  275.       s = ((Applet)this).getParameter("clic_sound_name");
  276.       if (s != null) {
  277.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  278.       }
  279.  
  280.    }
  281.  
  282.    public Color getColor(String param) {
  283.       String s = ((Applet)this).getParameter(param);
  284.       if (s != null) {
  285.          if (s.substring(0, 1).equals("#")) {
  286.             s = s.substring(1);
  287.             int i = Integer.parseInt(s, 16);
  288.             return new Color(i);
  289.          } else {
  290.             return null;
  291.          }
  292.       } else {
  293.          return null;
  294.       }
  295.    }
  296.  
  297.    public final void paint(Graphics g) {
  298.       if (this.paintable) {
  299.          this.field_2.clearRect(0, 0, this.field_0, this.field_1);
  300.          if (this.isBackImage & this.loaded) {
  301.             this.field_2.drawImage(this.backImage, (this.field_0 - this.wiBack) / 2, (this.field_1 - this.heBack) / 2, this);
  302.          }
  303.  
  304.          if (this.isText) {
  305.             this.field_2.drawString(this.text, this.decx, this.text_height + this.decy);
  306.          }
  307.  
  308.          g.drawImage(this.buffer, 0, 0, this);
  309.       }
  310.  
  311.    }
  312.  
  313.    public final void update(Graphics g) {
  314.       this.paint(g);
  315.    }
  316.  
  317.    public void showPopup(int x, int y) {
  318.       if (this.location.equals("mouse")) {
  319.          this.pop.show(this, x, y);
  320.       } else if (this.location.equals("center")) {
  321.          this.pop.show(this, this.field_0 / 2, this.field_1 / 2);
  322.       } else {
  323.          if (this.location.equals("random")) {
  324.             this.pop.show(this, (int)((double)this.field_0 * Math.random()), (int)((double)this.field_1 * Math.random()));
  325.          }
  326.  
  327.       }
  328.    }
  329.  
  330.    public void actionPerformed(ActionEvent event) {
  331.       if (((EventObject)event).getSource() instanceof MenuItem) {
  332.          if (this.clicSound != null) {
  333.             this.clicSound.play();
  334.          }
  335.  
  336.          String target = ((Applet)this).getParameter("target");
  337.          if (target == null) {
  338.             target = "_blank";
  339.          }
  340.  
  341.          URL u = this.giveURL(((MenuItem)((EventObject)event).getSource()).getActionCommand());
  342.          ((Applet)this).getAppletContext().showDocument(u, target);
  343.       }
  344.  
  345.    }
  346.  
  347.    public void stop() {
  348.       if (this.sound != null) {
  349.          this.sound.stop();
  350.       }
  351.  
  352.    }
  353.  
  354.    public URL giveURL(String url) {
  355.       try {
  356.          if (url.toUpperCase().startsWith("HTTP")) {
  357.             return new URL(url);
  358.          } else if (url.toUpperCase().startsWith("FTP")) {
  359.             int p = url.indexOf(":");
  360.             int p2 = url.indexOf(":", p + 1);
  361.             if (p2 != -1) {
  362.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  363.             }
  364.  
  365.             p = url.indexOf("%40");
  366.             if (p != -1) {
  367.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  368.             }
  369.  
  370.             return new URL(url);
  371.          } else {
  372.             return new URL(((Applet)this).getCodeBase(), url);
  373.          }
  374.       } catch (MalformedURLException e) {
  375.          System.out.println(e);
  376.          return null;
  377.       }
  378.    }
  379.  
  380.    public MenuPopUp() {
  381.       this.mode = "enter";
  382.       this.location = "mouse";
  383.       this.textColor = Color.black;
  384.       this.text_height = 10;
  385.       this.decx = 0;
  386.       this.decy = 0;
  387.       ((Component)this).addMouseListener(this);
  388.    }
  389.  
  390.    public void mouseClicked(MouseEvent e) {
  391.    }
  392.  
  393.    public void mouseEntered(MouseEvent e) {
  394.       if (this.statusBarText != null) {
  395.          ((Applet)this).showStatus(this.statusBarText);
  396.       }
  397.  
  398.       if (this.enterBackColor != null) {
  399.          ((Component)this).setBackground(this.enterBackColor);
  400.          ((Component)this).repaint();
  401.       }
  402.  
  403.       if (this.mode.equals("enter")) {
  404.          this.showPopup(e.getX(), e.getY());
  405.       }
  406.  
  407.    }
  408.  
  409.    public void mouseExited(MouseEvent e) {
  410.       if (this.enterBackColor != null) {
  411.          ((Component)this).setBackground(this.backColor);
  412.          ((Component)this).repaint();
  413.       }
  414.  
  415.    }
  416.  
  417.    public void mousePressed(MouseEvent e) {
  418.       if (this.mode.equals("clic")) {
  419.          this.showPopup(e.getX(), e.getY());
  420.       }
  421.  
  422.    }
  423.  
  424.    public void mouseReleased(MouseEvent e) {
  425.    }
  426. }
  427.